package com.example.swaggerproject.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@OpenAPIDefinition(
        servers = {
                @Server(description = "默认服务", url = "http://localhost:8090"),
                @Server(description = "测试服务", url = "http://localhost:8091"),
                @Server(description = "生产服务", url = "http://localhost:8092"),
                @Server(description = "开发服务", url = "http://localhost:8093")
        }
)
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("Swagger Project")
                        .description("Swagger Project 接口文档")
                        .version("v1.0.0")
                )
                .externalDocs(new ExternalDocumentation()
                        .description("更多文档")
                        .url("https://springdoc.org")
                );
    }

    @Bean
    public GroupedOpenApi uerOpenApi() {
        return GroupedOpenApi.builder()
                .group("用户服务")
                .pathsToMatch("/user/**")
                .build();
    }

    @Bean
    public GroupedOpenApi helloOpenApi() {
        return GroupedOpenApi.builder()
                .group("hello服务")
                .pathsToMatch("/hello/**", "/book/**")
                .build();
    }

}
